from toee import *
from utilities import *
from scripts import *
from council import *
from py00439script_daemon import record_time_stamp, get_v, set_v, npc_set, npc_unset, npc_get, tsc, within_rect_by_corners

def san_dialog( attachee, triggerer ):
	if (game.leader.reputation_has(32) == 1 or game.leader.reputation_has(30) == 1 or game.leader.reputation_has(29) == 1):
		attachee.float_line(11004,triggerer)
	elif (attachee.map == 5001):
		if ( anyone( triggerer.group_list(), "has_follower", 8000 ) and not anyone( triggerer.group_list(), "has_follower", 8014 )):
			attachee.float_line(1010,triggerer)
		elif ( anyone( triggerer.group_list(), "has_follower", 8014 ) and not anyone( triggerer.group_list(), "has_follower", 8000 )):
			attachee.float_line(1020,triggerer)
		elif ( anyone( triggerer.group_list(), "has_follower", 8014 ) and anyone( triggerer.group_list(), "has_follower", 8000 )):
			attachee.float_line(1030,triggerer)
		else:
			attachee.float_line(1000,triggerer)
	elif (anyone( triggerer.group_list(), "has_follower", 8014 ) and game.global_flags[309] == 0):
		game.global_flags[309] = 1
		triggerer.begin_dialog( attachee, 160 )
	elif (anyone( triggerer.group_list(), "has_follower", 8000 ) and game.global_flags[308] == 0):
		game.global_flags[308] = 1
		triggerer.begin_dialog( attachee, 170 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def argue( attachee, triggerer, line):
	npc = find_npc_near(attachee,14001)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,110)
	return SKIP_DEFAULT

def make_elmo_talk( attachee, triggerer, line):
	npc = find_npc_near(attachee,8000)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,110)
	return SKIP_DEFAULT

def make_otis_talk( attachee, triggerer, line):
	npc = find_npc_near(attachee,8014)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,110)
	return SKIP_DEFAULT


def san_first_heartbeat( attachee , triggerer ):
	if attachee.object_flags_get() & OF_OFF == 0:
		attachee.scripts[19] = 0
		attachee.scripts[10] = 0
	else:
		#if attachee.obj_get_int(379) == 0:
		#	attachee.obj_set_int(379, 1)
		#	game.obj_create(14806,location_from_axis(475,469))
		c_time = council_time()
		if attachee.map == 5063 and not (c_time == 1 or c_time == 5 or get_v(435) == 3 or get_v(435) == 4):
			attachee.object_flag_unset(OF_OFF)
			attachee.scripts[19] = 0
			attachee.scripts[10] = 0
	return

def san_heartbeat( attachee , triggerer ):
	if attachee.object_flags_get() & OF_OFF == 0:
		attachee.scripts[19] = 0
		attachee.scripts[10] = 0
	else:
		c_time = council_time()
		if attachee.map != 5001 and not (c_time == 1 or c_time == 5 or get_v(435) == 3 or get_v(435) == 4):
			attachee.object_flag_unset(OF_OFF)
			attachee.scripts[19] = 0
			attachee.scripts[10] = 0
	return
